﻿using System.Web.Mvc;
using AllIsWell.Core.Models;
using AllIsWell.Services.Infrastructure;

namespace AllIsWell.Web.Controllers
{
    public class PageController : Controller
    {
        private readonly IPageService _pageService;

        public PageController(IPageService pageService)
        {
            _pageService = pageService;
        }

        public ViewResult CreatePage(int destinyId)
        {
            var page = _pageService.GetFreshPage(destinyId);
            return View(page);
        }

        [HttpPost]
        public RedirectToRouteResult CreatePage(Page page)
        {
            var newPage = _pageService.CreatePage(page);

            TempData["GreetingMessage"] = newPage.Destiny.GreetingMessage;
            
            return RedirectToAction("GreetUser");
        }

        public ViewResult GreetUser()
        {
            ViewBag.GreetingMessage = TempData["GreetingMessage"];
            return View();
        }
    }
}
